package com.ruoyi.trans.service.impl;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.trans.domain.BaSupplier;
import com.ruoyi.trans.domain.BusTransportationDoc;
import com.ruoyi.trans.mapper.BaSupplierMapper;
import com.ruoyi.trans.mapper.BusTransportationDocMapper;
import com.ruoyi.trans.service.IBusTransportationDocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.text.Convert;

/**
 * 运输单据Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-05
 */
@Service
public class BusTransportationDocServiceImpl implements IBusTransportationDocService
{
    @Autowired
    private BusTransportationDocMapper busTransportationDocMapper;
    @Autowired
    private BaSupplierMapper baSupplierMapper;

    /**
     * 查询运输单据
     * 
     * @param dId 运输单据主键
     * @return 运输单据
     */
    @Override
    public BusTransportationDoc selectBusTransportationDocByDId(Long dId)
    {
        return busTransportationDocMapper.selectBusTransportationDocByDId(dId);
    }

    /**
     * 查询运输单据列表
     * 
     * @param busTransportationDoc 运输单据
     * @return 运输单据
     */
    @Override
    public List<BusTransportationDoc> selectBusTransportationDocList(BusTransportationDoc busTransportationDoc) {
       return  busTransportationDocMapper.selectBusTransportationDocList(busTransportationDoc);
    }

    @Override
    public Boolean checkDocUni(BusTransportationDoc doc) {
        int count = busTransportationDocMapper.countBusTransportationDoc(doc);
        return count >= 3;
    }

    /**
     * 新增运输单据
     * 
     * @param busTransportationDoc 运输单据
     * @return 结果
     */
    @Override
    public int insertBusTransportationDoc(BusTransportationDoc busTransportationDoc)
    {
        busTransportationDoc.setCreateTime(DateUtils.getNowDate());
        return busTransportationDocMapper.insertBusTransportationDoc(busTransportationDoc);
    }

    /**
     * 修改运输单据
     * 
     * @param busTransportationDoc 运输单据
     * @return 结果
     */
    @Override
    public int updateBusTransportationDoc(BusTransportationDoc busTransportationDoc)
    {
        busTransportationDoc.setUpdateTime(DateUtils.getNowDate());
        return busTransportationDocMapper.updateBusTransportationDoc(busTransportationDoc);
    }

    /**
     * 批量删除运输单据
     * 
     * @param dIds 需要删除的运输单据主键
     * @return 结果
     */
    @Override
    public int deleteBusTransportationDocByDIds(String dIds)
    {
        return busTransportationDocMapper.deleteBusTransportationDocByDIds(Convert.toStrArray(dIds));
    }

    /**
     * 删除运输单据信息
     * 
     * @param dId 运输单据主键
     * @return 结果
     */
    @Override
    public int deleteBusTransportationDocByDId(Long dId)
    {
        return busTransportationDocMapper.deleteBusTransportationDocByDId(dId);
    }
}
